//class for direct input... supports keyboard and mouse input

#ifndef _HELIX_DIRECT_INPUT_H_
#define _HELIX_DIRECT_INPUT_H_

#include <dinput.h>
#include "Helix.h"
#include "Input.h"

namespace helix		//Put this in the helix namespace
{

	//macro returns the element of an array given a key, and bitwise ands it with 0x80
	#define KEYDOWN(name, key) (name[key] & 0x80)

	class MY_CLASS DirectInput : public Input
	{
	private:
		char     buffer[256]; 

	protected:
		HRESULT hr;										//result... lets us catch errors
		LPDIRECTINPUT8 g_lpDI;							//the direct input object
		LPDIRECTINPUTDEVICE8 g_lpKeyboardDevice;		//the keyboard device pointer
		LPDIRECTINPUTDEVICE8 g_lpMouseDevice;			//the mouse device pointer
		bool available;									//flag to let us know if directinput is available or not
		bool keyboardAvailable;							//flag to let us know if the keyboard has been initialized
		bool mouseAvailable;							//flag to let us know if the mouse has been initialized
		DIMOUSESTATE mouseState;						//struct that holds our mouse data
		int mouseBufferSize;							//the size of our mouse buffer (currently, only immediate mode
														//is implemented, so this doesn't do anything yet)

		bool InitKeyboardDevice(HWND g_hwndMain);		//initialize the keyboard
		bool InitMouseDevice(HWND g_hwndMain);			//initialize the mouse
		bool UpdateKeyboardState();						//gets the current keyboard state
		bool UpdateMouseState();						//gets the current mouse state
		bool UpdateDeviceStates();						//gets both keyboard and mouse states
		void DI_Term();									//shut down direct input

	public:
		DirectInput();
		DirectInput(int bufferSize);
		DirectInput(HINSTANCE  g_hinst);				//initialize the direct input object
		virtual ~DirectInput();							//destructor

		void initialize(HINSTANCE g_hinst,HWND g_hwndMain);  //initializes direct input

		bool keyDown(unsigned char key);				//return true if the specified key is pressed
		bool mouseDown(unsigned char mouseButton);		//return true if the specified mouse button is pressed

		bool leftMouse();			//return true if the left mouse button is pressed
		bool rightMouse();			//return true if the right mouse button is pressed
		bool middleMouse();			//return true if the middle mouse button is pressed

		long getMouseX();			//get the current mouse position in the x direction (in pixels)
		long getMouseY();			//get the current mouse position in the y direction (in pixels)
		long getMouseZ();			//get the position of the mouse wheel 

		void update();				//do any kind of update that that input implementation might need per frame
	};


}  //End the helix namespace

#endif